<template>
  <div>
    <el-dialog :title="levelType === '2' ? '可降级别' : '可升级别'" :visible.sync="dialogFormVisible">
      <el-checkbox-group
        v-model="checkArray"
        @change="checkboxChange"
      >
        <el-checkbox v-for="item in levelList" :key="item.id" :label="item.id">{{ item.level_name }}</el-checkbox>
      </el-checkbox-group>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// import { getBrandsLevels } from '@/api/brand'
import { operationLevelUpDownApi } from '@/api/brand'
export default {
  props: {
  },
  data() {
    return {
      levelType: '1',
      dialogFormVisible: false,
      levelList: [],
      checkArray: [],
      brand_id: '',
      selLevelList: [],
      level_int: ''
    }
  },
  methods: {
    checkboxChange(val) {
      const that = this
      const arr = []
      val.forEach(item => {
        that.levelList.forEach(level => {
          if (item === level.id) {
            arr.push({ level_id: level.id, level_name: level.level_name, brand_id: level.brand_id, level_int: level.level_int })
          }
        })
      })
      console.log(arr)
      this.selLevelList = arr
      console.log(this.selLevelList)
    },
    submit() {
      const data = {
        type: this.levelType,
        brand_id: this.brand_id,
        level_int: this.level_int,
        pro: JSON.stringify(this.selLevelList)
      }
      console.log(data)
      operationLevelUpDownApi(data).then(res => {
        console.log(res)
        if (res.code === 200) {
          this.$message.success('设置成功！')
          this.dialogFormVisible = false
          this.$emit('reloadFun')
        }
      })
    }
  }
}
</script>

<style lang="sass" scoped>

</style>
